/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.Airway;
import com.sasis.dao.AirwayDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class AirwayDaoiBatis extends BaseDaoiBATIS implements AirwayDao {

    /**
     * @see com.sasis.dao.AirwayDao#getAirways(com.sasis.model.Airway)
     */
    public List getAirways(final Airway airway) {
          return getSqlMapClientTemplate().queryForList("getAirways", airway);
    }

    /**
     * @see com.sasis.dao.AirwayDao#getAirway(Integer id)
     */
    public Airway getAirway(Integer id) {
        Airway airway = (Airway) getSqlMapClientTemplate().queryForObject("getAirway", id);

        if (airway == null) {
            throw new ObjectRetrievalFailureException(Airway.class, id);
        }

        return airway;
    }

    /**
     * @see com.sasis.dao.AirwayDao#saveAirway(Airway airway)
     */    
    public void saveAirway(final Airway airway) {
        Integer id = airway.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addAirway", airway);
        } else {
            getSqlMapClientTemplate().update("updateAirway", airway);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(Airway.class, id);
        }
    }

    /**
     * @see com.sasis.dao.AirwayDao#removeAirway(Integer id)
     */
    public void removeAirway(Airway airway) {
        getSqlMapClientTemplate().update("deleteAirway",  airway);
    }
}
